﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DBUtility;

namespace OracleDAL.Sec
{
    /// <summary>
    /// 数据访问类UnitNode。
    /// </summary>
    public class UnitNode
    {
        public UnitNode()
        { }
        #region  成员方法


        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string UNITISN)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from SEC_UNIT_NODE");
            strSql.Append(" where UNITISN='" + UNITISN + "' ");
            return OracleHelper.Exists(strSql.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Model.Sec.UnitNode model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.UNITISN != null)
            {
                strSql1.Append("UNITISN,");
                strSql2.Append("'" + model.UNITISN + "',");
            }
            if (model.NODEID != null)
            {
                strSql1.Append("NODEID,");
                strSql2.Append("'" + model.NODEID + "',");
            }
            if (model.NODEISN != null)
            {
                strSql1.Append("NODEISN,");
                strSql2.Append("'" + model.NODEISN + "',");
            }
            strSql.Append("insert into SEC_UNIT_NODE(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return OracleHelper.ExecuteSql(strSql.ToString()) > 0 ? true : false;
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.Sec.UnitNode model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update SEC_UNIT_NODE set ");
            strSql.Append("NODEID='" + model.NODEID + "',");
            strSql.Append("NODEISN='" + model.NODEISN + "'");
            strSql.Append(" where UNITISN='" + model.UNITISN + "' ");
            return OracleHelper.ExecuteSql(strSql.ToString()) > 0 ? true : false;
        }
        public void Update(string nodeisn,string unitisn)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update SEC_UNIT_NODE set ");
            strSql.Append("NODEISN='" + nodeisn + "'");
            strSql.Append(" where UNITISN='" + unitisn + "' ");
            OracleHelper.ExecuteSql(strSql.ToString());
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string UNITISN)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete SEC_UNIT_NODE ");
            strSql.Append(" where UNITISN='" + UNITISN + "' ");
            OracleHelper.ExecuteSql(strSql.ToString());
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Sec.UnitNode GetModel(string UNITISN)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  ");
            strSql.Append(" UNITISN,NODEID,NODEISN ");
            strSql.Append(" from SEC_UNIT_NODE ");
            strSql.Append(" where UNITISN='" + UNITISN + "' ");
            Model.Sec.UnitNode model = new Model.Sec.UnitNode();
            DataSet ds = OracleHelper.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.UNITISN = ds.Tables[0].Rows[0]["UNITISN"].ToString();
                model.NODEID = ds.Tables[0].Rows[0]["NODEID"].ToString();
                model.NODEISN = ds.Tables[0].Rows[0]["NODEISN"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select UNITISN,NODEID,NODEISN ");
            strSql.Append(" FROM SEC_UNIT_NODE ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return OracleHelper.Query(strSql.ToString());
        }

        /*
        */

        #endregion  成员方法
    }
}
